const { defineConfig } = require('@vue/cli-service')
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
const webpack = require('webpack')
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const { name } = require('./package.json')

const isDevelopment = process.env.NODE_ENV === 'development' // 判断是否是生产环境

module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false, //关闭语法检查
  runtimeCompiler: true,
  configureWebpack: {
    plugins: [new NodePolyfillPlugin()],
    externals: {
      fs: require('fs'), //如果缺少其他模块就在下边加
    },
    resolve: {
      fallback: {
        crypto: require.resolve('crypto-browserify'),
      },
    },
  },
})

module.exports = {
  lintOnSave: false, //关闭语法检查
  // outputDir: './rm-dist',
  // publicPath: isDevelopment ? '/' : `/rm/`,
  outputDir: './portal-vue-dist',
  publicPath: isDevelopment ? '/' : `/portal-vue/`,
  productionSourceMap: isDevelopment,
  // devServer: {
  //   open: false,
  //   port: 3001,
  //   headers: {
  //     'Access-Control-Allow-Origin': '*',
  //   },
  // },
  devServer: {
    port: 3001,
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    proxy: {
      '/api': {
        // target: 'http://10.48.76.1',
        target: 'http://testcr.ouyeelf.com',
        changeOrigin: true,
        pathRewrite: {
          '^/api': '',
        },
      },
    },
    client: {
      overlay: false,
    },
  },
 
  configureWebpack: {
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
      new webpack.IgnorePlugin({
        resourceRegExp: /^fs$/, // 忽略所有对fs模块的引用
      }),
    ],
    output: {
      library: `${name}-[name]`,
      libraryTarget: 'umd', // 把微应用打包成 umd 库格式
      chunkLoadingGlobal: `webpackJsonp_${name}`,
    },
  },
}
